{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installing mmltoolkit\n",
    "\n",
    "To install, go to the mmltoolkit directory and run the command: <br>\n",
    "*python setup.py install*\n",
    "\n",
    "You may need to install several required packages (RDKit, etc). With Anaconda you can install RDKit in your default environment using the following commands: \n",
    "\n",
    "*conda config --add channels rdkit*\n",
    "\n",
    "*conda install rdkit*\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import a list of SMILES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('../../datasets/energetics_list_cleaned.csv') as file:\n",
    "    file.readline() # to skip the header \n",
    "    smiles = file.readlines()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create RDkit mol objects and add hydrogens "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from rdkit import Chem\n",
    "\n",
    "mol_list = [Chem.AddHs(Chem.MolFromSmiles(smile)) for smile in smiles]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create sum over bonds featurization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mmltoolkit.featurizations import sum_over_bonds\n",
    "\n",
    "bond_types, X_LBoB  = sum_over_bonds(mol_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Print out bond types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:N,N:N,C-N,C-C,C=O,C-O,C-H,H-O,C:C,N=O,N-O,H-N,N-N,C=N,N=N,C-Cl,C#N,N#N,F-N,C=C,C#C,C-F,N:O,C:O,O-O,Cl-N,Cl-O,F-O,N-Pb,I-N,N-Si,N=S,N-S,C-S,O=S,O-S,"
     ]
    }
   ],
   "source": [
    "for bond_type in bond_types:\n",
    "    print(bond_type+',', end='')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Save the feature vector array to a .csv file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "np.savetxt('sum_over_bonds.csv', X_LBoB.astype('int') , fmt='%i', delimiter=',')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Generate combined Estate+CDS+SoB feature vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mmltoolkit.featurizations import Estate_CDS_SoB_featurizer\n",
    "\n",
    "names_Estate_CDS_SoB, X_Estate_CDS_SoB = Estate_CDS_SoB_featurizer(mol_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
